package com.topka.buynewcar.android.pages;

import java.util.List;

import io.appium.java_client.android.AndroidDriver;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;

import com.topka.buynewcar.base.BasePage;

public class ChooseCarBrandPage extends BasePage {
	
	private WebElement sideBar;
	private String words = "ABCEDFGHIJKLMNOPQRSTUVWXYZ";

	public ChooseCarBrandPage(AndroidDriver wd) {
		super(wd);
	}
	
	public void clickSideBarWord(String word){
		sideBar = findViewById("sideBar");
		int height = sideBar.getSize().height;
		int width = sideBar.getSize().width;
		int x = sideBar.getLocation().getX();
		int y = sideBar.getLocation().getY();
		int wordHeight = height/26;
		int index = words.indexOf(word);
		int tapx = x+width/2;
		int tapy = y+index*wordHeight +wordHeight/2;
		wd.tap(1, tapx, tapy, 5);
	}

	public void clickCarBrand(String string) {
		List<WebElement> list = findViewsById("brandName");
		for(WebElement e : list){
			boolean flag = e.getText().equals(string);
			if(flag){
				e.click();
				return;
			}
		}
	}

}
